#pragma once

#include <QWidget>
#include <QVBoxLayout>
#include <QList>

class TabDrawer;
class DockTab;

/**
 * TabSidebar - 侧边栏
 * 管理多个TabDrawer（抽屉式标签页容器）
 */
class TabSidebar : public QWidget {
    Q_OBJECT
    
public:
    explicit TabSidebar(Qt::Edge edge = Qt::LeftEdge, QWidget* parent = nullptr);
    ~TabSidebar();
    
    // === 基础属性 ===
    Qt::Edge edge() const { return m_edge; }
    void setEdge(Qt::Edge edge);
    
    // === 抽屉管理 ===
    TabDrawer* addDrawer(const QString& title);
    TabDrawer* addDrawer(DockTab* tab);
    void removeDrawer(TabDrawer* drawer);
    void clear();
    
    // === 查询 ===
    int drawerCount() const { return m_drawers.size(); }
    QList<TabDrawer*> drawers() const { return m_drawers; }
    TabDrawer* drawerAt(int index) const;
    
    // === 状态管理 ===
    bool isEmpty() const { return m_drawers.isEmpty(); }
    TabDrawer* activeDrawer() const { return m_activeDrawer; }
    void setActiveDrawer(TabDrawer* drawer);

signals:
    void drawerAdded(TabDrawer* drawer);
    void drawerRemoved(TabDrawer* drawer);
    void activeDrawerChanged(TabDrawer* drawer);

protected:
    QSize sizeHint() const override;
    QSize minimumSizeHint() const override;

private slots:
    void onDrawerToggled(bool expanded);

private:
    void setupSidebar();
    void updateLayout();

private:
    Qt::Edge m_edge;
    QVBoxLayout* m_layout;
    QList<TabDrawer*> m_drawers;
    TabDrawer* m_activeDrawer;
    
    static const int SIDEBAR_WIDTH = 250;
    static const int COLLAPSED_WIDTH = 40;
};

